//#ifndef SELECTIONSORT_SORTTESTHELPER_H
//#define SELECTIONSORT_SORTTESTHELPER_H

#include<iostream>
#include<ctime>
#include<stdlib.h>
#include<cassert>
using namespace std;

namespace SortTestHelper{

    int* generateRandomArray(int n, int rangeL, int rangeR){

        assert( rangeL<rangeR );
        int *arr = new int[n];
        srand(time(NULL));
        for( int i=0; i<n; i++ )
            arr[i] = rand() % (rangeR-rangeL +1) + rangeL;
        return arr;
    }

    int* generateNearlyOderedArray(int n, int swapTimes){

        int *arr = new int[n];
        srand(time(NULL));
        for( int i=0; i<n; i++ )
            arr[i] = i;
        for(int i=0; i<swapTimes; i++){
            int posx = rand()%n;
            int posy = rand()%n;
            swap(arr[posx], arr[posy]);
        }
        return arr;
    }

    template<typename T>
        void printArray(T arr[], int n){
            for(int i=0; i<n; i++)
                cout << arr[i] << "; ";
            cout << endl;
            return;
        }

    template<typename T>
        bool isSorted(T arr[], int n){
            for(int i=0; i<n-1; i++)
                if (arr[i]>arr[i+1])
                    return false;
            return true;
        }

    template<typename T>
        void testSort( string sortName, void(*sort)(T[], int), T arr[], int n ){

            clock_t st = clock();
            sort(arr, n);
            clock_t pt = clock();
            assert(isSorted(arr, n));
            cout<< sortName << ": "<< double(pt - st)/CLOCKS_PER_SEC<<" s "<<endl;

            return;
        }

    // if T is a class or structure, deep copy should be conducted;
    template<typename T>
        T* copyArray(T a[], int n){
            T* arr = new int[n];
            copy(a, a+n, arr);//头指针，尾指针， 头指针
            return arr;
        }

}
